using System;

namespace CSharpPro._1106
{
    public class User
    {
        private string _username;
        private string _password;

        public string Username
        {
            get => _username;
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    throw new ArgumentException("用户名不可为空");
                if (value.Length < 3 || value.Length > 15)
                    throw new ArgumentException("用户名长度必须为3-15个字符");
                if (!System.Text.RegularExpressions.Regex.IsMatch(value, @"^[a-zA-Z0-9_]+$"))
                    throw new ArgumentException("用户名只能包含字母、数字、下划线");
                _username = value;
            }
        }

        public string Password
        {
            get => _password;
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    throw new ArgumentException("密码不可为空");
                if (value.Length < 6 || value.Length > 20)
                    throw new ArgumentException("密码长度必须为6-20个字符");
                if (!System.Text.RegularExpressions.Regex.IsMatch(value, @"^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).+$"))
                    throw new ArgumentException("密码必须包含至少1个大写字母、1个小写字母和1个数字");
                _password = value;
            }
        }

        public User(string username, string password)
        {
            Username = username;
            Password = password;
        }
    }
}